package pv.finder;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * manager setting of user
 * */
public class MySetting {

	public enum SEARCHMODE {
		WARD, DISTRIC, NEARLESS

	};

	public enum ROUTEMODE {
		DRIVING, WARLKING, BICYLING, TRANSIT
	};

	public enum MAPMODE {
		NORMAL, HYBRID, SATELLITE, TERRAIN
	};

	protected SEARCHMODE search = SEARCHMODE.WARD;
	protected ROUTEMODE route = ROUTEMODE.DRIVING;
	protected MAPMODE map = MAPMODE.NORMAL;

	protected static String SEARCH_MODE = "SEARCHMODE";
	protected static String ROUTE_MODE = "ROUTEMODE";
	protected static String MAP_MODE = "MAPMODE";

	public ROUTEMODE getRoute() {
		return route;
	}

	public void setRoute(ROUTEMODE route) {
		this.route = route;
	}

	public MAPMODE getMap() {
		return map;
	}

	public void setMap(MAPMODE map) {
		this.map = map;
	}

	public SEARCHMODE getSearch() {
		return search;
	}

	public void setSearch(SEARCHMODE search) {
		this.search = search;
	}

	public void restoreSetting(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				MySetting.class.toString(), Context.MODE_PRIVATE);
		int iSearch = sharedPreferences.getInt(SEARCH_MODE, 0);
		this.search = iSearch == 0 ? SEARCHMODE.WARD
				: iSearch == 1 ? SEARCHMODE.DISTRIC : SEARCHMODE.NEARLESS;

		int iRoute = sharedPreferences.getInt(ROUTE_MODE, 0);
		this.route = iRoute == 0 ? ROUTEMODE.DRIVING
				: iRoute == 1 ? ROUTEMODE.WARLKING
						: iRoute == 2 ? ROUTEMODE.BICYLING : ROUTEMODE.TRANSIT;

		int iMap = sharedPreferences.getInt(MAP_MODE, 0);
		this.map = iMap == 0 ? MAPMODE.NORMAL : iMap == 1 ? MAPMODE.HYBRID
				: iMap == 2 ? MAPMODE.SATELLITE : MAPMODE.TERRAIN;

	}

	public void saveSetting(Context context) {
		SharedPreferences.Editor editor = context.getSharedPreferences(
				MySetting.class.toString(), Context.MODE_PRIVATE).edit();
		editor.putInt(SEARCH_MODE, this.search.ordinal());
		editor.putInt(ROUTE_MODE, this.route.ordinal());
		editor.putInt(MAP_MODE, this.map.ordinal());
		editor.apply();

	}

	/* singleton */
	private static MySetting instance = new MySetting();

	public static synchronized MySetting getInstance() {
		if (instance == null) {
			instance = new MySetting();
		}
		return instance;
	}

}
